package com.forum.module.system.api.oauth2;

import com.forum.framework.common.pojo.DataResult;
import com.forum.module.system.api.oauth2.dto.OAuth2AccessTokenCheckRespDTO;
import com.forum.module.system.api.oauth2.dto.OAuth2AccessTokenCreateReqDTO;
import com.forum.module.system.api.oauth2.dto.OAuth2AccessTokenRespDTO;
import com.forum.module.system.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author zihan.ouyang
 */
@FeignClient(name = ApiConstants.NAME)
@Tag(name = "认证服务 HTTP API - OAuth2.0 令牌")
//@RequestMapping(ApiConstants.PREFIX + "/oauth2/token")
//@RestController
@Validated
public interface OAuth2TokenApi {

    String PREFIX = ApiConstants.PREFIX + "/oauth2/token";

    /**
     * 校验 Token 的 URL 地址，主要是提供给 Gateway 使用
     */
    @SuppressWarnings("HttpUrlsUsage")
    String URL_CHECK = "http://" + ApiConstants.NAME + PREFIX + "/check";

    @PostMapping(PREFIX + "/create")
    @Operation(summary = "创建访问令牌")
    DataResult<OAuth2AccessTokenRespDTO> createAccessToken(@Valid @RequestBody OAuth2AccessTokenCreateReqDTO reqDTO);

    @GetMapping(PREFIX + "/check")
    @Operation(summary = "检查访问令牌")
    @Parameter(name = "accessToken", description = "访问令牌", required = true)
    DataResult<OAuth2AccessTokenCheckRespDTO>  checkAccessToken(@RequestParam("accessToken") String accessToken);

    @DeleteMapping(PREFIX + "/remove")
    @Operation(summary = "移除访问令牌")
    @Parameter(name = "accessToken", description = "访问令牌", required = true)
    DataResult<OAuth2AccessTokenRespDTO> removeAccessToken(@RequestParam("accessToken") String accessToken);

    @PostMapping(PREFIX + "/refresh")
    @Operation(summary = "刷新访问令牌")
    @Parameter(name = "refreshToken", description = "刷新令牌", required = true)
    DataResult<OAuth2AccessTokenRespDTO> refreshAccessToken(@RequestParam("refreshToken") String refreshToken);
}
